
package org.movee.spring.data.hugegraph.repository.config;

import org.movee.spring.data.hugegraph.repository.HugeRepository;
import org.movee.spring.data.hugegraph.repository.factory.HugeRepositoryFactoryBean;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.data.repository.config.AnnotationRepositoryConfigurationSource;
import org.springframework.data.repository.config.RepositoryConfigurationExtensionSupport;
import org.springframework.util.StringUtils;

import java.util.Collection;
import java.util.Collections;

public class HugeRepositoryConfigurationExtension extends RepositoryConfigurationExtensionSupport {

    // private final Logger logger = LoggerFactory.getLogger(this.getClass());

    /* (non-Javadoc)
     * @see org.springframework.data.repository.config.RepositoryConfigurationExtensionSupport#getModulePrefix()
     */
    @Override
    public String getModulePrefix() {
        return "huge";
    }


    /* (non-Javadoc)
 * @see org.springframework.data.repository.config.RepositoryConfigurationExtension#getRepositoryFactoryBeanClassName()
 */
    @Override
    public String getRepositoryFactoryBeanClassName() {
        return HugeRepositoryFactoryBean.class.getName();
    }


    /* (non-Javadoc)
     * @see org.springframework.data.repository.config.RepositoryConfigurationExtensionSupport#getIdentifyingTypes()
     */
    @Override
    public Collection<Class<?>> getIdentifyingTypes() {
        return Collections.singleton(HugeRepository.class);
    }

    /* (non-Javadoc)
     * @see org.springframework.data.repository.config.RepositoryConfigurationExtensionSupport#postProcess(org.springframework.beans.factory.support.BeanDefinitionBuilder, org.springframework.data.repository.config.AnnotationRepositoryConfigurationSource)
     */
    @Override
    public void postProcess(BeanDefinitionBuilder builder, AnnotationRepositoryConfigurationSource config) {

        String hugeTemplateRef = config.getAttributes().getString("hugeTemplateRef");

        if (StringUtils.hasText(hugeTemplateRef)) {
            builder.addPropertyReference("hugeTemplate", hugeTemplateRef);
        }
    }
}

